﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.BLL;
using Automobile.service.Model;
namespace Automobile.service.UI
{
    public partial class CommodityShow : System.Web.UI.Page
    {
        ProductBLL bll = new ProductBLL();
        public static int id;
        public void LoadData()
        {
     
           string Product_Name=this.Product_Name.Value;
            string Product_Modelspe=this.Product_Modelspe.Value;
            this.AspNetPager1.RecordCount = bll.Product_Count(Product_Name, Product_Modelspe,Convert.ToInt32(this.DropDownList1.SelectedValue));//设置总行数;
            this.Repeater1.DataSource = bll.Product_show(3, this.AspNetPager1.CurrentPageIndex);//设置数据源
            this.Repeater1.DataBind();//绑定数据源
            this.AspNetPager1.PageSize = 3;//设置每页显示的行数
        }
        public void Loadxiala()
        {
            this.DropDownList1.DataSource = bll.Product_Type_Show();//返回的是DataTable，将其绑定到控件,获取数据源
            //显示“请选择”
            ListItem lt = new ListItem();
            this.DropDownList1.DataValueField = "Product_Type_Id";//控件绑定值
            this.DropDownList1.DataTextField = "Product_Type_Name";//控件显示的字段
            this.DropDownList1.DataBind(); //进行绑定
            lt.Text = "-->请选择级别<--";//绑定的请选择
            lt.Value = "0";//赋值
            lt.Selected = true;
            DropDownList1.Items.Add(lt);
          
              
        
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                Loadxiala();
                LoadData();
                id = Convert.ToInt32(this.DropDownList1.SelectedValue);
                string Product_Name = this.Product_Name.Value;
                string Product_Modelspe = this.Product_Modelspe.Value;
                Session["count"] = bll.Product_Count(Product_Name, Product_Modelspe,Convert.ToInt32(this.DropDownList1.SelectedValue));
            }

        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string eName = e.CommandName;//获取当前要执行的命令名称
            string stuID = e.CommandArgument.ToString();//获取当前绑定的主键值
            switch (eName)
            {
                case "Del":
                    if (bll.Del(Convert.ToInt32(stuID)) > 0)
                    {
                        Response.Write("<script>alert('删除成功！');</script>");
                        LoadData();
                        
                    }
                    else
                    {
                        Response.Write("<script>alert('删除失败！');</script>");
                    }
                    break;
                case "Upt":
                    Response.Redirect("CommodityEdit.aspx?id=" + stuID);
                    break;
            }

        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            LoadData();
        }

        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            this.AspNetPager1.RecordCount = bll.Product_Count(this.Product_Name.Value, this.Product_Modelspe.Value,Convert.ToInt32(this.DropDownList1.SelectedValue));//设置总行数;
          
            this.Repeater1.DataSource = bll.Product_show_Sel(3, this.AspNetPager1.CurrentPageIndex, this.Product_Name.Value, this.Product_Modelspe.Value,Convert.ToInt32(this.DropDownList1.SelectedValue));//设置数据源
            this.Repeater1.DataBind();//绑定数据源
      
        }
    }
}